package com.cpi.cornpp.plants.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.cpi.cornpp.plants.form.PlantForm;
import com.cpi.cornpp.plants.services.PlantService;
import com.cpi.cornpp.plants.view.PlantView;

/**
 * 
 * @author Edgar Joao
 *
 */
public class PlantGoEditAction extends Action{

	private final static String DEFAULT = "goEditPlants";//$NON-NLS-1$
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		PlantView plantView = null;
		PlantView plantViewSearch = null;
		PlantService service = null;
		PlantForm plantForm = null;
		String plantId = null;
		
		plantId = request.getParameter("plantId");
		plantViewSearch = new PlantView();
		plantViewSearch.setPlantId(Integer.parseInt(plantId));
		plantForm = (PlantForm) form;
		
		service = new PlantService();		
		plantView = service.getPlant(plantViewSearch);
		plantForm.setPlantView(plantView);
		
		return mapping.findForward(DEFAULT);
	}
}
